package com.zxt.smartplatform.dto;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.zxt.smartplatform.exceptions.ResultCode;

//只解析不为空的数据,注意"" 也算空,也就是只返回有效数据

@JsonInclude(JsonInclude.Include.NON_EMPTY)

public class R {

    private int code;//状态码,
    private String msg;//提示信息

    private Object data;//携带的数据


    public static R setOK() {
        return setOK(null);
    }


    public static R setOK(Object data) {
       /*
        R result = new R();
        result.setCode(ResultCode.SUCCESS);
        result.setMsg("成功");
        result.setData(data);
        return result;

        */

        return setError(ResultCode.SUCCESS, "成功", data);
    }


    public static R setError(int code, String msg) {
        return setError(code, msg, null);
    }

    public static R setError(int code, String msg, Object data) {
        R result = new R();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


}